package com.yinhe.module.cjl;
import com.yinhe.common.annotation.Log;
import com.yinhe.common.core.controller.BaseController;
import com.yinhe.common.core.domain.AjaxResult;
import com.yinhe.common.core.page.TableDataInfo;
import com.yinhe.common.enums.BusinessType;
import com.yinhe.common.utils.poi.ExcelUtil;
import com.yinhe.system.domain.YhContractFile;
import com.yinhe.system.service.IYhContractFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/module/cjl/data")
public class CjlDataController extends BaseController{
    @Autowired
    private IYhContractFileService yhContractFileService;

    /**
     * 查询合同资料列表
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(YhContractFile yhContractFile)
    {
        startPage();
        List<YhContractFile> list = yhContractFileService.selectYhContractFileList(yhContractFile);
        return getDataTable(list);
    }

    /**
     * 导出合同资料列表
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:data:export')")
    @Log(title = "合同资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YhContractFile yhContractFile)
    {
        List<YhContractFile> list = yhContractFileService.selectYhContractFileList(yhContractFile);
        ExcelUtil<YhContractFile> util = new ExcelUtil<YhContractFile>(YhContractFile.class);
        util.exportExcel(response, list, "合同资料数据");
    }

    /**
     * 获取合同资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:data:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yhContractFileService.selectYhContractFileById(id));
    }

    /**
     * 新增合同资料
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:data:add')")
    @Log(title = "合同资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YhContractFile yhContractFile)
    {
        long represent = Long.parseLong(yhContractFile.getNote1());
        yhContractFile.setDeptId(represent);
        return toAjax(yhContractFileService.insertYhContractFile(yhContractFile));
    }

    /**
     * 修改合同资料
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:data:edit')")
    @Log(title = "合同资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YhContractFile yhContractFile)
    {
        long represent = Long.parseLong(yhContractFile.getNote1());
        yhContractFile.setDeptId(represent);
        return toAjax(yhContractFileService.updateYhContractFile(yhContractFile));
    }

    /**
     * 删除合同资料
     */
    @PreAuthorize("@ss.hasPermi('module:cjl:data:remove')")
    @Log(title = "合同资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yhContractFileService.deleteYhContractFileByIds(ids));
    }
}


